<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
<!--
	function viewFunction(id){
		window.location.href = "./functionTree.do?action=viewFunction&id="+id;
		window.location.target = "main";
	}
	
	function addFunction(){
		window.location.href = "./functionTree.do?action=preAddFunction";
		window.location.target = "main";
	}
	
	function updateFunction(id){
		window.location.href = "./functionTree.do?action=preUpdateFunction&id="+id;
		window.location.target = "main";
	}
	
	function deleteFunction(id,parentId){
		if(confirm("<fmt:message key='common.message.delete'/>")){
			window.location.href = "./functionTree.do?action=deleteFunction&id="+id+"&parentId="+parentId;
			window.location.target = "main";
		}
	}
	
	function addOperate(id){
		window.location.href = "./operate.do?action=preAddOperate&functionId="+id;
		window.location.target = "main";
	}
	
	function updateOperate(id){
		window.location.href = "./operate.do?action=preUpdateOperate&functionId="+id;
		window.location.target = "main";
	}
	
	function initPage(result){
		if(result == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage('${result}')">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='func.title.main'/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:addFunction();" title="<fmt:message key='common.button.add'/>" hidefocus="true"><fmt:message key='common.button.add'/></a>
						</td>
						<td></td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table2" cellpadding="0" cellspacing="0" >
					<tr>
						<td>
							<table class="table_lab" cellpadding="0" cellspacing="0">
								<tr>
									<td class="title">
										&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='func.title.main'/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
								<tr>
									<td valign="top">
										<div style="width:100%;height:420px;overflow-x: hidden;overflow-y: scroll;">
										<table class="table_style">
											<tr>
												<td class="title4"><fmt:message key='func.lable.funcName'/></td>
												<td class="title4" width=""><fmt:message key='func.lable.parent'/></td>
												<td class="title4" width="15%"><fmt:message key='common.lable.isActivity'/></td>
												<td class="title4" width="15%"><fmt:message key='common.lable.operate'/></td>
											</tr>
											<c:forEach var="function" items="${functions}">
											<c:if test="${function.parentId == 0}">
											<tr>
												<td>
													<a href="javascript:viewFunction('${function.id}');">
														<font color="red">
														<c:choose>
															<c:when test="${language == 2}">${function.functionNameEn}</c:when>
															<c:otherwise>${function.functionName}</c:otherwise>
														</c:choose>
														</font>
													</a>
												</td>
												<td>-</td>
												<td>
													<c:choose>
														<c:when test="${function.isActivity == 1}"><fmt:message key='common.lable.is'/></c:when>
														<c:otherwise><fmt:message key='common.lable.no'/></c:otherwise>
													</c:choose>
												</td>
												<td>
													<img class="btn_img" src="./images/a_update.gif" onclick="updateFunction(${function.id})" title="<fmt:message key='common.button.update'/>">&nbsp;&nbsp;
													<img class="btn_img" src="./images/a_del.gif" onclick="deleteFunction(${function.id},${function.parentId})" title="<fmt:message key='common.button.delete'/>">&nbsp;&nbsp;
												</td>
											</tr>
											
											<c:forEach var="sFunction" items="${functions}">
											<c:if test="${sFunction.parentId == function.id}">
											<tr>
												<td>
													<a href="javascript:viewFunction('${sFunction.id}');">
													<c:choose>
														<c:when test="${language == 2}">${sFunction.functionNameEn}</c:when>
														<c:otherwise>${sFunction.functionName}</c:otherwise>
													</c:choose>
													</a>
												</td>
												<td>
													<c:choose>
														<c:when test="${language == 2}">${function.functionNameEn}</c:when>
														<c:otherwise>${function.functionName}</c:otherwise>
													</c:choose>
												</td>
												<td>
													<c:choose>
														<c:when test="${sFunction.isActivity == '1'}"><fmt:message key='common.lable.is'/></c:when>
														<c:otherwise><fmt:message key='common.lable.no'/></c:otherwise>
													</c:choose>
												</td>
												<td>
													<img class="btn_img" src="./images/a_update.gif" onclick="updateFunction(${sFunction.id})" title="<fmt:message key='common.button.update'/>">&nbsp;&nbsp;
													<img class="btn_img" src="./images/a_del.gif" onclick="deleteFunction(${sFunction.id},${sFunction.parentId})" title="<fmt:message key='common.button.delete'/>">&nbsp;&nbsp;
													<img class="btn_img" src="./images/a_addaction.gif" onclick="addOperate(${sFunction.id})" title="<fmt:message key='func.button.addOperate'/>">&nbsp;&nbsp;
													<img class="btn_img" src="./images/a_updateaction.gif" onclick="updateOperate(${sFunction.id})" title="<fmt:message key='func.button.updateOperate'/>">&nbsp;&nbsp;
												</td>
											</tr>
											</c:if>
											</c:forEach>
											
											</c:if>
											</c:forEach>
										</table>
										</div>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>